package cc.fine.svc.main.controller;

import cc.fine.svc.common.utils.R;
import cc.fine.svc.main.bean.po.TblUser;
import cc.fine.svc.main.bean.vo.UserVo;
import cc.fine.svc.main.service.AccountService;
import cc.fine.svc.main.service.qiniu.QiniuKodoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * @AUTHOR: wyihe
 * @DATE: 2023/10/25
 */
@RestController
@RequestMapping("/account")
@Api(description = "账户")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @Autowired
    private QiniuKodoService kodoService;


    @PostMapping("/register/for/password")
    @ApiOperation("注册用户，通过密码注册")
    public R register(@Valid UserVo vo) {
        if (StringUtils.isEmpty(vo.getAvatar())) {
            vo.setAvatar("");
        }

        if (StringUtils.isEmpty(vo.getSelfIntroduce())) {
            vo.setSelfIntroduce("");
        }



        return accountService.registerForPassword(vo);


    }

    @PostMapping("/login/for/password")
    @ApiOperation("通过手机号密码登录")
    public R login(String phone, String password) {
        return accountService.login(phone, password);
    }
}
